<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
    <title>设备归还</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/rent/rentInfo.css">
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <style>
        body #myForm .help-block, html #myForm .help-block {
            margin-left: 127px;
            margin-bottom:5px;
        }
        #backStatus{
            background:none !important
        }
        .btn{
            width:100px;
            line-height:15px;
            background:#35acfd;
            color:white;
        }
        #backTime{
            padding:0 !important;
        }
        #backStatus{
            padding-left:10px;
        }
    </style>
    <script>
        $(document).ready(function () {
            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    backTime: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    backStatus: {
                        validators: {
                            notEmpty: true
                        }
                    }
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();
                $.ajax({
                    url: '${URL_RENT_UPDATEBACK}',
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    error: function () {
                        alert('error');
                    },
                    success: function (data) {
                        closeFrame();
                    }
                });
            });

            initLayDate("#backTime");
//            initDateTime("#backTime");
            //initInstr("#instrumentId");

            //如果是新增，显示数量字段，否则隐藏。
            var method = "${method}";
            if (method == "1") {
                if (typeof($("#div_num").attr("hidden")) == "undefined") {

                } else {
                    $("#div_num").removeAttr("hidden");
                }
            } else {
                $("#div_num").attr("hidden", "true");
            }
        });

        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }

        function initLayDate(id){
            laydate({
                elem: id,
                istime: true,
                format: 'YYYY-MM-DD',
                choose:function(dates){ //选择好日期的回调
                    $('#myForm').bootstrapValidator('revalidateField', $('#backTime'));
                }
            })
        }
        function initInstr(id) {
            $(id).select2({
                placeholder: '请选择设备',
                ajax: {
                    url: '${URL_BASE_SELECTINSTRUMENT}',
                    dataType: 'json',
                    type: "post",
                    delay: 250,
                    data: function (params) {
                        var data = new Object();
                        data["limit"] = 10;
                        if (params.page == undefined) {
                            data["offset"] = 0;
                        } else {
                            data["offset"] = (params.page - 1) * 10;
                        }
                        if (params.term != undefined) {
                            data["name"] = params.term;
                        }
                        return data;
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        return {
                            results: data.data,
                            pagination: {
                                more: (params.page * 10) < data.msg
                            }
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 0,
                templateResult: formatRepo, // omitted for brevity, see the source of this page
                templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
            });
        }
        function formatRepo(repo) {
            if (repo.loading) return repo.text;
            var markup = "<div class='select2-result-repository clearfix'>" +
                "<div class='select2-result-repository__title'>" + repo.text + '|' + repo.instrumentBrand + "</div></div>";
            return markup;
        }

        function formatRepoSelection(repo) {
            $("#instrumentId").val(repo.id);
            return repo.text;
        }


        function initDateTime(id){
            var t = $(id).datetimepicker({
                language:  'zh-CN',
                weekStart:  0,
                todayBtn: true,
                autoclose:  1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            }).on('hide',function(e) {
                $('#myForm').bootstrapValidator('revalidateField', $('#backTime'));
            });

        }

    </script>
</head>
<body style="width: 98%" >
<div class="header">
    <h1>设备归还</h1>
</div>
<form id="myForm" class="form-horizontal" method="post">
    <div class="clearfix">
        <div class="form-group mg">
            <label class="control-label" style="width:110px;">租借编号</label>
            <input type="text" id="rentId" name="rentId" class="form-control" value="${entity.rentId}"
                       readonly="readonly">
        </div>
        <div class="form-group">
            <label class="control-label" style="width:110px;">归还日期</label>
            <div id="TimeArea" class="input-group date form_date">
                <input type="text" id="backTime" name="backTime" class="form-control" placeholder="选择日期" value="${entity.backTime}" readonly>
            </div>
        </div>
        <div class="form-group mg">
            <label class="control-label" style="width:110px;">返还押金</label>
            <input type="text" id="backMoney" name="backMoney" class="form-control" value="${entity.backMoney}">
        </div>
        <div class="form-group">
            <label class="control-label" style="width:110px;">归还状态</label>
            <select id="backStatus" name="backStatus" class="form-control">
                <medi:configOpt name="backStatus" key="${entity.backStatus}"/>
            </select>
        </div>
        <div class="form-group mg">
            <label class="control-label" style="width:110px;">归还备注</label>
            <input type="text" id="backComment" name="backComment" class="form-control"
                       value="${entity.backComment}">
        </div>
    </div>
    <div class="form-group submitBtn">
        <button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">关闭</button>
        <button type="submit" name="submit" class="btn">保存</button>
    </div>
</form>
</body>
</html>